package Vista;

import java.awt.Color;
import java.awt.Insets;
import java.awt.event.ActionListener;


import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class NewAccount {
	
	private JPanel mainPanel;
	private JLabel jlb_nombre, jlb_apellido, jlb_mail, jlb_padron, jlb_pass, jlb_pass2;
	private JTextField jtf_nombre, jtf_apellido, jtf_mail, jtf_padron;
	private JPasswordField jpf_pass, jpf_pass2;
	private JButton jb_atras, jb_guardar;
	
	public NewAccount() {
		initComponents();
	}

	protected void clearTextFields() {
		jtf_nombre.setText("");
		jtf_apellido.setText("");
		jtf_mail.setText("");
		jtf_padron.setText("");
		jpf_pass.setText("");
		jpf_pass2.setText("");
	}
	
	private void initComponents() {
		
		mainPanel = new JPanel();
		
		mainPanel.setLayout(null);
		mainPanel.add(getJLabelNombre());
		mainPanel.add(getJLabelApellido());
		mainPanel.add(getJLabelPadron());
		mainPanel.add(getJLabelPass());
		mainPanel.add(getJLabelPass2());
		mainPanel.add(getJLabelMail());
		mainPanel.add(getJTextFieldNombre());
		mainPanel.add(getJTextFieldApellido());
		mainPanel.add(getJTextFieldPadron());
		mainPanel.add(getJPasswordFieldPass());
		mainPanel.add(getJPasswordFieldPass2());
		mainPanel.add(getJTextFieldMail());
		mainPanel.add(getJButtonAtras());
		mainPanel.add(getJButtonOk());
		mainPanel.setSize(700, 500);
	}

	private JButton getJButtonAtras() {
		if (jb_atras == null) {
			jb_atras = new JButton();
			jb_atras.setText("<< Atras");
			jb_atras.setMargin(new Insets(1, 5, 1, 5));
			jb_atras.setBounds(375,400,100, 40);
		}

		return jb_atras;
	}
	
	public void BackActionListener(ActionListener listener) {
	    jb_atras.addActionListener(listener);
	}

	private JButton getJButtonOk() {
		if (jb_guardar == null) {
			jb_guardar = new JButton();
			jb_guardar.setText("Guardar");
			jb_guardar.setMargin(new Insets(1, 5, 1, 5));
			jb_guardar.setBounds(500,400,100, 40);
		}
		return jb_guardar;
	}
	
	public void SaveActionListener(ActionListener listener) {
	    jb_guardar.addActionListener(listener);
	}

	private JTextField getJTextFieldNombre() {
			if (jtf_nombre == null) {
				jtf_nombre = new JTextField();
				jtf_nombre.setBounds(225, 100, 250, 25); 
			}
			return jtf_nombre;
	}
	
	private JTextField getJTextFieldApellido() {
		if (jtf_apellido == null) {
			jtf_apellido = new JTextField();
			jtf_apellido.setBounds(225, 150, 250, 25); 
		}
		return jtf_apellido;
}
	
	private JTextField getJTextFieldMail() {
		if (jtf_mail == null) {
			jtf_mail = new JTextField();
			jtf_mail.setBounds(225, 250, 250, 25); 
		}
		return jtf_mail;
}
	public int getPadron() {
		
		return Integer.parseInt(jtf_padron.getText());
	}
	
	public String getStringPadron() {
		return jtf_padron.getText();
	}
	
	public String getPass() {
		return new String(jpf_pass.getPassword());
	}
	
	public String getPass2() {
		return new String(jpf_pass2.getPassword());
	}
	
	public String getNombre() {
		return jtf_nombre.getText();
	}
	public String getApellido() {
		return jtf_apellido.getText();
	}
	
	public String getMail() {
		return jtf_mail.getText();
	}
	
	private JTextField getJTextFieldPadron() {
		if (jtf_padron == null) {
			jtf_padron = new JTextField();
			jtf_padron.setBounds(225, 200, 250, 25); 
		}
		return jtf_padron;
	}
	
	private JPasswordField getJPasswordFieldPass() {
		if (jpf_pass == null) {
			jpf_pass = new JPasswordField();
			jpf_pass.setBounds(225, 300, 250, 25); 
		}
		return jpf_pass;
	}
	
	private JPasswordField getJPasswordFieldPass2() {
		if (jpf_pass2 == null) {
			jpf_pass2 = new JPasswordField();
			jpf_pass2.setBounds(225, 350, 250, 25); 
		}
		return jpf_pass2;
	}
	
	private JLabel getJLabelNombre() {
		if (jlb_nombre == null) {
			jlb_nombre = new JLabel();
			jlb_nombre.setText("Nombre: ");
			jlb_nombre.setForeground(Color.gray);
			jlb_nombre.setBounds(100, 100, 100, 20); 
		}
		return jlb_nombre;
	}
	
	private JLabel getJLabelApellido() {
		if (jlb_apellido == null) {
			jlb_apellido = new JLabel();
			jlb_apellido.setText("Apellido: ");
			jlb_apellido.setForeground(Color.gray);
			jlb_apellido.setBounds(100, 150, 100, 20); 
		}
		return jlb_apellido;
	}
	
	private JLabel getJLabelPadron() {
		if (jlb_padron == null) {
			jlb_padron = new JLabel();
			jlb_padron.setText("Nro padrón: ");
			jlb_padron.setForeground(Color.gray);
			jlb_padron.setBounds(100, 200, 100, 20); 
		}
		return jlb_padron;
	}
	
	private JLabel getJLabelMail() {
		if (jlb_mail == null) {
			jlb_mail = new JLabel();
			jlb_mail.setText("Mail: ");
			jlb_mail.setForeground(Color.gray);
			jlb_mail.setBounds(100, 250, 100, 20); ; 
		}
		return jlb_mail;
	}
	
	private JLabel getJLabelPass() {
		if (jlb_pass == null) {
			jlb_pass = new JLabel();
			jlb_pass.setText("Contraseña: ");
			jlb_pass.setForeground(Color.gray);
			jlb_pass.setBounds(100, 300, 100, 20); ; 
		}
		return jlb_pass;
	}

	private JLabel getJLabelPass2() {
		if (jlb_pass2 == null) {
			jlb_pass2 = new JLabel();
			jlb_pass2.setText("Contraseña: ");
			jlb_pass2.setForeground(Color.gray);
			jlb_pass2.setBounds(100, 350, 100, 20); ; 
		}
		return jlb_pass2;
	}
	
	public JComponent getMainComponent() {
		      return mainPanel;
	}

}
